package io.renren.modules.wms.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import io.renren.utils.ValidationUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.wms.entity.DailyTempEntity;
import io.renren.modules.wms.service.DailyTempService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author lain
 * @email 494576412@qq.com
 * @date 2019-08-02 16:58:26
 */
@RestController
@RequestMapping("wms/dailytemp")
public class DailyTempController {
    @Autowired
    private DailyTempService dailyTempService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("wms:dailytemp:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dailyTempService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 重新生成模板
     */
    @RequestMapping("/reGenTemp")
    @RequiresPermissions("wms:dailytemp:list")
    public R reGenTemp(@RequestParam Map<String, Object> params){
        List<DailyTempEntity> list = dailyTempService.list();
        List<Integer> idList = null;
        if(ValidationUtil.isNotEmptyList(list)){
            idList = list.stream().map(el -> el.getWeiboId()).collect(Collectors.toList());
        }
        params.put("idList", idList);
        dailyTempService.removeAll();
        PageUtils page = dailyTempService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("wms:dailytemp:info")
    public R info(@PathVariable("id") Integer id){
		DailyTempEntity dailyTemp = dailyTempService.getById(id);

        return R.ok().put("dailyTemp", dailyTemp);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("wms:dailytemp:save")
    public R save(@RequestBody DailyTempEntity dailyTemp){
		dailyTempService.save(dailyTemp);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("wms:dailytemp:update")
    public R update(@RequestBody DailyTempEntity dailyTemp){
		dailyTempService.updateById(dailyTemp);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("wms:dailytemp:delete")
    public R delete(@RequestBody Integer[] ids){
		dailyTempService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
